package com.ss.android.article.base.feature.message;

import android.content.Context;
import android.content.res.Resources;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.account.Spipe;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.c.ImageManager;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.article.common.model.UserRole;
import com.ss.android.common.app.LifeCycleMonitor;
import com.ss.android.image.loader.ImageLoader;
import com.ss.android.newmedia.a.TimeFormatter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class d extends BaseAdapter implements AbsListView.RecyclerListener, LifeCycleMonitor {
    final class a {
        public String a;
        public int b;
        public int c;

        a() {

        }
    }

    public interface b {
        void a(int arg1, int arg2, m arg3);
    }

    final class c {
        View a;
        View b;
        NightModeAsyncImageView c;
        ImageView d;
        TextView e;
        TextView f;
        TextView g;
        TextView h;
        View i;
        TextView j;
        m k;
        int l;
        b m;
        final View.OnClickListener n;

        public c(b arg2) {
            this.n = new e(this);
            this.m = arg2;
        }
    }

    private static int[] a;
    private Context b;
    private LayoutInflater c;
    private Resources d;
    private int e;
    private List f;
    private b g;
    private TaskInfo h;
    private AppData i;
    private ImageLoader j;
    private ImageLoader k;
    private ImageManager l;
    private TimeFormatter m;

    static {
        a = new int[]{17, 15, 19, 21};
    }

    public d(Context arg10, List arg11, int arg12, b arg13) {
        int v7;
        int v3 = 8;
        Spipe.inst();
        this.i = AppData.getInstance();
        this.b = arg10;
        this.e = arg12;
        this.f = arg11;
        this.g = arg13;
        this.c = LayoutInflater.from(arg10);
        this.h = new TaskInfo();
        this.l = new ImageManager(arg10);
        this.d = arg10.getResources();
        if (this.e == 4) {
            v7 = this.d.getDimensionPixelSize(R.dimen.il);
            this.k = new ImageLoader(this.b, this.h, v3, v3, 1, this.l, v7, v7);
        } else {
            v7 = this.d.getDimensionPixelSize(R.dimen.ik);
            this.j = new ImageLoader(this.b, this.h, v3, v3, 1, this.l, v7, v7);
        }

        this.m = new TimeFormatter(arg10);
    }

    private static boolean a(m arg3) {
        boolean v0;
        if (arg3 == null) {
            v0 = false;
        } else {
            if (arg3.j >= com.ss.android.article.base.feature.message.m.a.first.intValue() && arg3.j <= com.ss.android.article.base.feature.message.m.a.second.intValue()) {
                return true;
            }

            v0 = false;
        }

        return v0;
    }

    public final void onDestroy() {
        ImageLoader v2 = null;
        if (this.j != null) {
            this.j.onDestroy();
        }

        if (this.k != null) {
            this.k.onDestroy();
        }

        this.h.a = true;
        this.j = v2;
        this.k = v2;
    }

    public final void onResume() {
        if (this.j != null) {
            this.j.onPause();
        }

        if (this.k != null) {
            this.k.onPause();
        }
    }

    public final void onPause() {
    }

    public final int getCount() {
        return this.f.size();
    }

    public final Object getItem(int arg2) {
        return this.f.get(arg2);
    }

    public final long getItemId(int arg3) {
        return ((long) arg3);
    }

    public final View getView(int arg17, View arg18, ViewGroup arg19) {
        View v2_1;
        Object v6_1;
        View v5;
        int v3;
        Object v2 = this.f.get(arg17);
        com.ss.android.article.base.feature.update.a.a v7 = v2 != null ? ((com.ss.android.article.base.feature.update.a.e) v2).a : null;
        if (arg18 == null) {
            v3 = this.e == 4 ? R.layout.j_ : R.layout.jb;
            v5 = this.c.inflate(v3, arg19, false);
            c v4 = new c(this.g);
            v4.a = this.e == 4 ? v5.findViewById(com.ss.android.article.browser.R.id.adb) : v5.findViewById(com.ss.android.article.browser.R.id.ad9);
            v4.b = v5.findViewById(com.ss.android.article.browser.R.id.avatar_layout);
            v4.c = v5.findViewById(com.ss.android.article.browser.R.id.avatar);
            v4.d = v5.findViewById(com.ss.android.article.browser.R.id.mark_v);
            v5.findViewById(com.ss.android.article.browser.R.id.adc);
            v4.e = v5.findViewById(com.ss.android.article.browser.R.id.add);
            v4.f = v5.findViewById(com.ss.android.article.browser.R.id.adf);
            v4.g = v5.findViewById(com.ss.android.article.browser.R.id.adg);
            v4.h = v5.findViewById(com.ss.android.article.browser.R.id.adh);
            v4.i = v5.findViewById(com.ss.android.article.browser.R.id.divider);
            v4.j = v5.findViewById(com.ss.android.article.browser.R.id.ade);
            if (this.g != null) {
                v4.a.setOnClickListener(v4.n);
                v4.e.setOnClickListener(v4.n);
                v4.b.setOnClickListener(v4.n);
            }

            v5.setTag(v4);
            v6_1 = v4;
        } else {
            v5 = arg18;
            v6_1 = arg18.getTag();
        }

        if ((((c) v6_1)) != null) {
            ((c) v6_1).c.adaptNightMode(AppData.isNightMode());
            ((c) v6_1).d.setImageDrawable(this.d.getDrawable(com.ss.android.article.browser.R.drawable.mh));
            if (this.e == 4 || !a(((c) v6_1).k)) {
                ((c) v6_1).e.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.update_comment_more_text_selector));
            } else {
                ((c) v6_1).e.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.ssxinzi4));
            }

            ((c) v6_1).h.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.ssxinzi9));
            ((c) v6_1).f.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.wy));
            ((c) v6_1).g.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.ssxinzi1));
            ((c) v6_1).i.setBackgroundColor(this.d.getColor(com.ss.android.article.browser.R.color.ssxinxian1));
        }

        if (v7 == null) {
            v2_1 = v5;
        } else {
            ((c) v6_1).k = ((m) v7);
            ((c) v6_1).l = this.e;
            if (this.e != 5 || !a(((m) v7))) {
                if (((m) v7).o != null && !android.support.design.a.isTextEmpty(((m) v7).o.screenName)) {
                    ((c) v6_1).e.setText(((m) v7).o.screenName);
                    ((c) v6_1).e.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.update_comment_more_text_selector));
                }

                ((c) v6_1).j.setVisibility(View.GONE);
                if (((m) v7).o != null && ((m) v7).o.userRole != null && !android.support.design.a.isTextEmpty(((m) v7).o.userRole.mRoleName)) {
                    UserRole v3_1 = ((m) v7).o.userRole;
                    ((c) v6_1).j.setVisibility(View.VISIBLE);
                    TextView v4_1 = ((c) v6_1).j;
                    if (v4_1 != null && v3_1 != null) {
                        v4_1.setText(v3_1.mRoleName);
                        switch (com.ss.android.article.base.utils.l.a[v3_1.mDisplayType.ordinal()]) {
                            case 1: {
                                v4_1.setTextColor(v4_1.getResources().getColor(com.ss.android.article.browser.R.color.pa));
                                v4_1.setBackgroundResource(com.ss.android.article.browser.R.drawable.c0);
                                break;
                            }
                            case 2: {
                                v4_1.setTextColor(v4_1.getResources().getColor(com.ss.android.article.browser.R.color.p_));
                                v4_1.setBackgroundResource(com.ss.android.article.browser.R.drawable.bz);
                                break;
                            }
                            default:
                                v4_1.setTextColor(v4_1.getResources().getColor(com.ss.android.article.browser.R.color.pb));
                                v4_1.setBackgroundResource(com.ss.android.article.browser.R.drawable.c1);
                                break;
                        }


                    }
                }

                if (((m) v7).o == null || !((m) v7).o.userVerified) {
                    ((c) v6_1).d.setVisibility(View.GONE);
                } else {
                    ((c) v6_1).d.setVisibility(View.VISIBLE);
                }

                if (((m) v7).o == null) {
                } else if (android.support.design.a.isTextEmpty(((m) v7).o.avatarUrl)) {
                } else {
                    ((c) v6_1).c.setUrl(((m) v7).o.avatarUrl);
                }
            } else {
                ((c) v6_1).e.setTextColor(this.d.getColor(com.ss.android.article.browser.R.color.ssxinzi4));
                UIUtils.setMaxLines(((c) v6_1).e, 0);
                ((c) v6_1).e.setText(this.d.getString(com.ss.android.article.browser.R.string.update_system_notification));
                ((c) v6_1).d.setVisibility(View.GONE);
                ((c) v6_1).j.setVisibility(View.GONE);
                ((c) v6_1).c.setImageDrawable(this.d.getDrawable(com.ss.android.article.browser.R.drawable.ug));
            }

            ((c) v6_1).f.setVisibility(View.GONE);
            v3 = this.i.mFontSizePref;
            if (v3 < 0 || v3 > 3) {
                v3 = 0;
            }

            ((c) v6_1).g.setTextSize(((float) a[v3]));
            if (this.e == 4 && (v7 == null || ((m) v7).j < com.ss.android.article.base.feature.message.m.c.first.intValue() || ((m) v7).j > com.ss.android.article.base.feature.message.m.c.second.intValue())) {
                ((c) v6_1).g.setCompoundDrawablesWithIntrinsicBounds(this.d.getDrawable(com.ss.android.article.browser.R.drawable.ns), null, null, null);
                ((c) v6_1).g.setText("");
            } else {
                ((c) v6_1).g.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
                if (android.support.design.a.isTextEmpty(((m) v7).k)) {
                } else {
                    if (this.e == 5) {
                        TextView v8 = ((c) v6_1).g;
                        String v7_1 = ((m) v7).k;
                        if (!android.support.design.a.isTextEmpty(v7_1) && (v7_1.contains("http"))) {
                            ArrayList v9 = new ArrayList();
                            Pattern v3_2 = Patterns.WEB_URL;
                            Linkify.MatchFilter v10 = Linkify.sUrlMatchFilter;
                            Matcher v11 = v3_2.matcher(((CharSequence) v7_1));
                            int v12 = v7_1.length();
                            int v4_2;
                            for (v3 = 0; v11.find(); v3 = v4_2) {
                                int v13 = v11.start();
                                v4_2 = v11.end();
                                if (v13 < v3) {
                                    break;
                                }

                                if (v13 >= v4_2) {
                                    break;
                                }

                                if (v4_2 > v12) {
                                    break;
                                }

                                if (v10.acceptMatch(((CharSequence) v7_1), v13, v4_2)) {
                                    String v14 = v11.group(0);
                                    if (TTUtils.isValidUrl(v14)) {
                                        v3 = v4_2 >= v12 || v7_1.charAt(v4_2) != 47 || (v7_1.contains("?")) ? v4_2 : v4_2 + 1;
                                        a v4_3 = new a();
                                        v4_3.a = v14;
                                        v4_3.b = v13;
                                        v4_3.c = v3;
                                        v9.add(v4_3);
                                        continue;
                                    }
                                }
                            }

                            if (v9.isEmpty()) {
                                v8.setText(((CharSequence) v7_1));
                            } else {
                                SpannableString v4_4 = new SpannableString(((CharSequence) v7_1));
                                Iterator v7_2 = v9.iterator();
                                while (v7_2.hasNext()) {
                                    Object v3_3 = v7_2.next();
                                    v4_4.setSpan(new HttpURLSpan(((a) v3_3).a), ((a) v3_3).b, ((a) v3_3).c, 33);
                                }
                                v8.setText(((CharSequence) v4_4));
                                v8.setMovementMethod(LinkMovementMethod.getInstance());
                            }
                        } else {
                            v8.setText(((CharSequence) v7_1));
                        }
                    } else {
                        ((c) v6_1).g.setText(((m) v7).k);
                    }
                }
            }

            label_223:
            ((c) v6_1).h.setText(this.m.a(((com.ss.android.article.base.feature.update.a.e) v2).a.s * 1000));
            v2_1 = v5;
        }

        return v2_1;
    }

    public final void onStop() {
        if (this.j != null) {
            this.j.onStop();
        }

        if (this.k != null) {
            this.k.onStop();
        }
    }

    public final void onMovedToScrapHeap(View arg4) {
        m v2 = null;
        Object v0 = arg4.getTag();
        if ((v0 instanceof c)) {
            ((c) v0).k = v2;
            ((c) v0).c.setTag(v2);
            ((c) v0).c.setUrl(((String) null));
        }
    }
}

